home *** CD-ROM | disk | FTP | other *** search
/ Info-Mac 4 / Info_Mac IV CD-ROM (Pacific HiTech Inc.)(August 1994).iso / Development / Source / Telnet 2.6.1d1 4⁄26⁄94 Folder / source / main / errors.c < prev    next >
Text File  |  1994-04-14  |  6KB  |  223 lines

  1. /*
  2. *    errors.c
  3. *    This file handles all of the error printing in one centralized place.
  4. *    There are several classes of errors (network, memory, etc).
  5. *    To Handle an error, just call into DoError with the appropriate
  6. *    mask and error number.  The routine goes from there.
  7. *
  8. *
  9. *****************************************************************
  10. *    NCSA Telnet for the Macintosh                                *
  11. *                                                                *
  12. *    National Center for Supercomputing Applications                *
  13. *    Software Development Group                                    *
  14. *    152 Computing Applications Building                            *
  15. *    605 E. Springfield Ave.                                        *
  16. *    Champaign, IL  61820                                        *
  17. *                                                                *
  18. *    Copyright (c) 1986-1992,                                    *
  19. *    Board of Trustees of the University of Illinois                *
  20. *****************************************************************
  21. *  Revisions:
  22. *  7/92        Telnet 2.6:    Initial version.  Scott Bulmahn
  23. */
  24.  
  25.  
  26. #ifdef MPW
  27. #pragma segment 7
  28. #endif
  29.  
  30. #include <stdio.h>
  31. #include <string.h>
  32.  
  33. #include "TelnetHeader.h"
  34. #include "InternalEvents.h"
  35. #include "telneterrors.h"
  36. #include "DlogUtils.proto.h"
  37. #include "mainseg.proto.h"                // for forcequit proto
  38.  
  39.  
  40. #include "errors.proto.h"
  41. /*================================= ERROR HANDLING CODE ============================*/
  42. /* This is the main error handling code.  Get all the errors out of the resource    */
  43. /* file.  The resource number that contains the errors depends on what error        */
  44. /* class we are talking about                                                        */
  45. void DoError(short code, short level, char *mess1)
  46. {
  47.     char buffer1[256],buffer2[256];
  48.     short dItem;
  49.     DialogPtr dtemp;
  50.  
  51.     buffer1[0]=0;        /* dont print extraneous garbage to the screen... */
  52.     buffer2[0]=0;
  53.  
  54.     switch (code & ERRORMASK)
  55.         {
  56.         case NET_ERRORCLASS:
  57.         case MEMORY_ERRORCLASS:
  58.         case RESOURCE_ERRORCLASS:
  59.             strncpy( buffer1, geterrstring(code), 255);
  60.             if (mess1) strncpy(buffer2, mess1, 255);
  61.             break;
  62.  
  63.  
  64.         case NOCODE:                        /* no code given, just 2 strings */
  65.             strncpy(buffer1, mess1, 255);
  66.         }
  67.  
  68.     if (level ==2 || level ==3)                
  69.     {                
  70.         c2pstr(buffer1);
  71.         c2pstr(buffer2);
  72.         ParamText((StringPtr) buffer1,(StringPtr) buffer2,"\p","\p");
  73.  
  74.         dtemp=GetNewDialog(OopsDLOG,(Ptr) 0L,kInFront);    /* Put up the error notice */
  75.         ModalDialog(DLOGwOKUPP,&dItem);        /* Get an event */
  76.         DisposDialog(dtemp);            /* Take it off.....all off......*/
  77.     }
  78. }
  79.  
  80. /************************************************************************/
  81. /*  geterrstring
  82. *   returns the string associated with a particular error number
  83. *    NOTE: strings moved to resource # 23237 
  84. *   error number is formatted %4d at the beginning of the string
  85. */
  86.  
  87.  
  88. char *geterrstring(short code)
  89. {
  90.     short i;
  91.     char s[10];
  92.     Str255 ErrorString;                                    /* BYU 2.4.16 */
  93.     short errorResource, numberOfErrors;
  94.     
  95.     switch (code & ERRORMASK)
  96.         {
  97.         case NET_ERRORCLASS:
  98.             errorResource = NETERROR_RESOURCE_ID;
  99.             numberOfErrors = NETERROR_RESOURCE_COUNT;
  100.             break;
  101.         case MEMORY_ERRORCLASS:
  102.             errorResource = MEMERROR_RESOURCE_ID;
  103.             numberOfErrors = MEMERROR_RESOURCE_COUNT;
  104.             break;
  105.         case RESOURCE_ERRORCLASS:
  106.             errorResource = RESERROR_RESOURCE_ID;
  107.             numberOfErrors = RESERROR_RESOURCE_COUNT;
  108.             break;
  109.         }
  110.  
  111.     code &= FLAGMASK;    
  112.     sprintf(s,"%4d",code);
  113.  
  114.  
  115.     for (i=1; i <= numberOfErrors; i++) 
  116.         {            
  117.         GetIndString(ErrorString,errorResource,i);    
  118.         p2cstr(ErrorString);                            
  119.         if (!strncmp((char *) ErrorString,s,4))            
  120.             return((char *) ErrorString + 5);            
  121.         }                                                
  122.         
  123.     GetIndString(ErrorString, errorResource,1);        
  124.     return((char *) ErrorString+5);                        
  125. }
  126.  
  127. void    FatalCancelAlert(short messageID, StringPtr DefaultButtonString, short InternalID, short MacID)
  128. {
  129.     Str255        errorString, numberString, numberString2;
  130.     DialogPtr    theDialog;
  131.     short        Type, ditem = 3;
  132.     Handle        Itemh;
  133.     Rect        Box;
  134.  
  135.     GetIndString(errorString, GENERAL_MESSAGES_ID, messageID);
  136.     NumToString((long)InternalID, numberString);
  137.     NumToString((long)MacID, numberString2);
  138.     ParamText(errorString, numberString, numberString2, NULL);
  139.     
  140.     theDialog = GetNewMyDialog(FATALCANCEL_ID, NULL, kInFront, (void *)ThirdCenterDialog);
  141.  
  142.     GetDItem(theDialog, DLOGOk, &Type, &Itemh, &Box);
  143.     SetCTitle((ControlHandle)Itemh, DefaultButtonString);
  144.     ShowWindow(theDialog);
  145.  
  146.     while (ditem > 2)    ModalDialog(DLOGwOK_CancelUPP, &ditem);
  147.     DisposeDialog(theDialog);
  148.     
  149.     // If the user chose quit, then do it... else return.
  150.     if (ditem == DLOGCancel)    forcequit();
  151. }
  152.  
  153. void    FatalAlert(short messageID, short InternalID, short MacID)
  154. {
  155.     Str255        errorString, numberString, numberString2;
  156.     DialogPtr    theDialog;
  157.     short        ditem = 3;
  158.  
  159.     GetIndString(errorString, GENERAL_MESSAGES_ID, messageID);
  160.     NumToString((long)InternalID, numberString);
  161.     NumToString((long)MacID, numberString2);
  162.     ParamText(errorString, numberString, numberString2, NULL);
  163.     
  164.     theDialog = GetNewMyDialog(FATAL_ID, NULL, kInFront, (void *)ThirdCenterDialog);
  165.     ShowWindow(theDialog);
  166.  
  167.     while (ditem > 1)    ModalDialog(DLOGwOKUPP, &ditem);
  168.     
  169.     forcequit();        // It's a fatal error, so quit
  170. }
  171.  
  172. void    OperationFailedAlert(short messageID, short InternalID, short MacID)
  173. {
  174.     Str255        errorString, numberString, numberString2;
  175.     DialogPtr    theDialog;
  176.     short        ditem = 3;
  177.  
  178.     GetIndString(errorString, OPFAILED_MESSAGES_ID, messageID);
  179.     NumToString((long)InternalID, numberString);
  180.     NumToString((long)MacID, numberString2);
  181.     ParamText(errorString, numberString, numberString2, NULL);
  182.     
  183.     theDialog = GetNewMyDialog(OPFAILED_ID, NULL, kInFront, (void *)ThirdCenterDialog);
  184.     ShowWindow(theDialog);
  185.  
  186.     while (ditem > 1)    ModalDialog(DLOGwOKUPP, &ditem);
  187.     DisposeDialog(theDialog);
  188. }
  189.  
  190. void    OutOfMemory(short InternalID)
  191. {
  192.     OperationFailedAlert(OUT_OF_MEMORY, InternalID, 0);
  193. }
  194.  
  195. // Returns "TRUE" if default button is hit.
  196. Boolean    AskUserAlert(short messageID, Boolean CancelIsDefault)
  197. {
  198.     Str255        errorString;
  199.     DialogPtr    theDialog;
  200.     short        Type, ditem = 3;
  201.     Handle        Itemh;
  202.     Rect        Box;
  203.  
  204.     GetIndString(errorString, GENERAL_MESSAGES_ID, messageID);
  205.     ParamText(errorString, NULL, NULL, NULL);
  206.     
  207.     theDialog = GetNewMyDialog(ASKUSER_ID, NULL, kInFront, (void *)ThirdCenterDialog);
  208.  
  209.     if (!CancelIsDefault) {        // We need to swap cancel and ok buttons
  210.         GetDItem(theDialog, DLOGOk, &Type, &Itemh, &Box);
  211.         SetCTitle((ControlHandle)Itemh, "\pOK");
  212.         GetDItem(theDialog, DLOGCancel, &Type, &Itemh, &Box);
  213.         SetCTitle((ControlHandle)Itemh, "\pCancel");
  214.         }
  215.         
  216.     ShowWindow(theDialog);
  217.  
  218.     while (ditem > 2)    ModalDialog(DLOGwOK_CancelUPP, &ditem);
  219.     DisposeDialog(theDialog);
  220.     
  221.     if (ditem == 1) return (TRUE);
  222.     else return (FALSE);
  223. }